import 'package:cached_network_image/cached_network_image.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/a_yyt/models/care_report_entity.dart';
import 'package:ls_work/net/net.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/util/utils.dart' as u;
import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/widgets/gallery_photo_browser.dart';

import '../../login/page/user_manager.dart';
import '../../res/dimens.dart';

class CareReportCell extends StatelessWidget {
  final BeanInfo? info;
  Function()? deleteClick;
  CareReportCell({Key? key, this.info,this.deleteClick});

  @override
  Widget build(BuildContext context) {
    List<int> titleList = [];
    if (info?.attachList != null && info!.attachList!.length > 0) {
      for (var f in info!.attachList!) {
        print(f.id);
        titleList.add(f.id);
      }
    }
    return Container(
      padding: EdgeInsets.all(20),
      width: ScreenUtil.getScreenW(context),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text.rich(
                TextSpan(children: [
                  TextSpan(
                      text: '${info?.elderName??""}   ',
                      style: TextStyles.textBoldDark16),
                  TextSpan(
                    text: "${info?.bedNo??""}",
                    style: TextStyles.textDark14,
                  ),
                ]),
              ),
              Text(
                '${info?.recordTime??""}',
                style: TextStyles.textGray16,
              ),
            ],
          ),
          SizedBox(
            height: 12,
          ),
          Text(
            '记录人：${info?.recorder??""}',
            style: TextStyles.textDark14,
          ),
          SizedBox(
            height: 12,
          ),
          Container(
            width: ScreenUtil.getScreenW(context),
            padding: EdgeInsets.all(8),
            child: Text(
              '${info?.content??""}',
              style: TextStyle(
                fontSize: Dimens.font_sp14,
                color: Colours.text_normal,
              ),
              overflow: TextOverflow.ellipsis,
              maxLines: 5,
            ),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(4),
                color: Colours.bg_color),
          ),
          SizedBox(
            height: 10,
          ),
          titleList.length <= 0
              ? Container()
              : GridView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  itemCount: titleList.length,
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 4,
                    mainAxisSpacing: 10,
                    crossAxisSpacing: 10,
                  ),
                  itemBuilder: (BuildContext context, int index) {
                    return InkWell(
                      onTap: () {

                        var list = titleList
                            .map((e) => "${HttpApi.imageDownLoadUrl}${e}")
                            .toList();
                        Go().push(ShowImagePage(
                          list,
                          position: index,
                        ));
                      },
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(6),
                        child: CachedNetworkImage(
                          width: (ScreenUtil.getScreenW(context) - 32 - 20) / 4,
                          height:
                              (ScreenUtil.getScreenW(context) - 32 - 20) / 4,
                          fit: BoxFit.cover,
                          imageUrl:
                              '${HttpApi.imageDownLoadUrl}${titleList[index]}',
                            httpHeaders: {"Cookie":UserManager.cookieStr},
                          placeholder: (context, url) => new u.ProgressView(),
                          errorWidget: (context, url, error) => new Icon(
                            Icons.error,
                            color: Colors.black,
                          ),
                        ),
                      ),
                    );
                  },
                ),
          // if(info.delete)
          TextButton(
            onPressed: () {
              if(deleteClick!=null){
                deleteClick!();
              }
            },
            child: CommonText('删除'),
            style: ButtonStyle(
                minimumSize: WidgetStateProperty.all(
                    Size(MediaQuery.of(context).size.width, 40))),
          )
        ],
      ),
    );
  }
}
